#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : gtmsAutoTestProject 
@File    : base_middle_api.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/4/25 18:36 
@Describe: 餐饮中台接口请求基类
"""
from APIs.base_api import BaseApi
from Config.yamlRead import middleLoginInfo_cfg


class BaseMiddleApi(BaseApi):
    def __init__(self, environment):
        """
        构造函数
        :param environment: 品牌编码
        """
        super().__init__()  # 继承父类构造函数
        self.type = "餐饮中台"
        self.url = middleLoginInfo_cfg[environment]['middle_api_url']  # 取出配置文件URL前缀
        credentials_sql = "SELECT token FROM login_credentials WHERE environment = '{}' AND type = '餐饮中台'".format(environment)
        self.token = self.sqlite.find_data(credentials_sql)[0][0]  # 取出sqlite中台请求token

    def get_headers(self) -> object:
        """
        获取中台接口请求头
        :return:
        """
        headers = {
            'Connection': 'keep-alive',
            'j_token': self.token,
            'Content-Type': 'application/json; charset=UTF-8',
            'sec-ch-ua-mobile': '?0',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
            'Accept': '*/*',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Dest': 'empty',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'Cookie': 'SERVERID=k8s-ingress.gtmsh.com:10080; j_token=' + self.token
        }
        return headers


if __name__ == '__main__':
    test = BaseMiddleApi('sit')
    url = 'catering-backend/shop/base/list'
    payload = '{"brandCode":"823882","shopCode":"5999"}'
    test.http_requests(url, payload)
